package com.arithmetic.version1;

import java.util.*;
import static org.junit.Assert.*;
import org.junit.Test;

public class BinaryOperationTester {

    @Test
    public void testConstructorAndAccessors() {
        BinaryOperation op = new BinaryOperation(5, 3, '+');
        assertEquals(5, op.getLeftOperand());
        assertEquals(3, op.getRightOperand());
        assertEquals('+', op.getOperator());
        assertEquals(8, op.getValue());
    }

    @Test
    public void testToString() {
        BinaryOperation op = new BinaryOperation(5, 3, '+');
        assertEquals("5 + 3 = ", op.toString());
    }

    @Test
    public void testEquals() {
        BinaryOperation op1 = new BinaryOperation(5, 3, '+');
        BinaryOperation op2 = new BinaryOperation(5, 3, '+');
        BinaryOperation op3 = new BinaryOperation(5, 3, '-');

        assertTrue(op1.equals(op2));
        assertFalse(op1.equals(op3));
    }

    @Test
    public void testGenerateAdditionOperation() {
        BinaryOperation op = BinaryOperation.generateAdditionOperation();
        assertTrue(op.getOperator() == '+');
        assertTrue(op.getValue() == op.getLeftOperand() + op.getRightOperand());
    }

    @Test
    public void testGenerateSubstractOperation() {
        BinaryOperation op = BinaryOperation.generateSubstractOperation();
        assertTrue(op.getOperator() == '-');
        assertTrue(op.getValue() == op.getLeftOperand() - op.getRightOperand());
        assertTrue(op.getValue() >= 0); // 确保减法结果非负
    }
}
